package com.nkzy.mapper;

import com.nkzy.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Create by 王建烨 on 2022/3/10 9:24
 **/

public interface UserMapper {
    /**
     * 查询所有用户
     *
     * @return List<User>
     */
    @Select("select * from `user`")
    List<User> findAll();

    /**
     * 查询一个用户
     *
     * @param id
     * @return User
     */
    @Select("select * from `user` where `id`=#{id}")
    User findUserById(Integer id);

    /**
     * 更新(删除、插入)用户
     *
     * @param user
     */
    @Update("update `user` set `username`=#{username},`password`=#{password},`email`=#{email} where `id`=#{id}")
    void updateUser(User user);

    /**
     * 删除用户
     *
     * @param id
     */
    @Delete("delete from `user` where `id`=#{id}")
    void deleteUser(Integer id);

    /**
     * 添加用户
     *
     * @param user
     */
    @Insert("insert into `user` (`username`,`password`,`email`) values (#{username},#{password},#{email})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addUser(User user);
}
